#include <bits/stdc++.h>
using namespace std;
const int maxn=2*1e5+7;
long long a[maxn];
int T;
int n;
long long ans;
void dfs(int x,int rx,int ry,long long sum)
{
    if(x>n)
    {
        ans=max(ans,sum);
        return;
    }
    bool g=0;
    if(a[x]==a[rx] && rx>=1)
    {
        g=1;
        sum+=a[x];
    }
    dfs(x+1,x,ry,sum);
    if(g)
        sum-=a[x];
    if(a[x]==a[ry] && ry>=1)
        sum+=a[x];
    dfs(x+1,rx,x,sum);


}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        ans=0;

        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        dfs(1,-1,-1,0);

        printf("%lld\n",ans);
    }
    return 0;
}
